package csu.webcourse.mypetstore.web.servlet;

import csu.webcourse.mypetstore.domain.Account;
import csu.webcourse.mypetstore.domain.Product;
import csu.webcourse.mypetstore.service.LogService;
import net.sourceforge.stripes.action.RedirectResolution;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

public class SignoffFormServlet extends HttpServlet {

    private Account account;

    private List<Product> myList;
    private boolean authenticated;

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();

        Account account = (Account) session.getAttribute("loginAccount");
        if (account != null) {
            HttpServletRequest httpRequest = req;
            String strBackUrl = "http://" + req.getServerName() + ":" + req.getServerPort()
                    + httpRequest.getContextPath() + httpRequest.getServletPath() + "?" + (httpRequest.getQueryString());

            LogService logService = new LogService();
            //最后加入的信息“XXXXX”应当为该界面的信息以及一些商品信息
            String logInfo = logService.logInfo(" ") + strBackUrl + "用户退出登录，回到主界面";
            logService.insertLogInfo(account.getUsername(), logInfo);
        }
        clear();
        session.invalidate();
        resp.sendRedirect("mainForm");
    }
    public void clear() {
        account = new Account();
        myList = null;
        authenticated = false;
    }
}
